{% extends "app/base_site.html" %}
{% block title %} 行为算法管理 {% endblock title %}
{% block stylesheets %}
  {{ block.super }}
<style>
    .xc_behaviour-container {
        /*background: #f5f7fa;*/
    }
    
    .xc_modern-card {
        background: white;
        border-radius: 6px;
        padding: 10px 14px;
        box-shadow: 0 1px 3px rgba(0,0,0,0.06);
        margin-bottom: 12px;
    }
    
    .xc_page-header {
        display: flex;
        justify-content: flex-start !important;
        align-items: center;
        padding: 4px 0;
        margin-bottom: 8px;
        min-height: 32px;
        gap: 8px;
        flex-wrap: wrap;
    }
    
    .xc_page-title {
        display: flex;
        align-items: center;
        font-size: 18px;
        font-weight: 400;
        flex-shrink: 0;
    }
    
    .xc_page-title i {
        margin-right: 6px;
        font-size: 16px;
        color: #3b82f6;
    }
    
    .xc_header-right {
        display: flex;
        align-items: center;
        gap: 8px;
    }
    
    .xc_header-actions {
        display: flex;
        align-items: center;
        gap: 6px;
        flex-shrink: 0;
    }
    
    .xc_loading-spinner {
        display: inline-block;
        width: 12px;
        height: 12px;
        border: 2px solid #e5e7eb;
        border-top: 2px solid #3b82f6;
        border-radius: 50%;
        animation: xc_spin 1s linear infinite;
        margin-right: 5px;
    }
    
    @keyframes xc_spin {
        0% { transform: rotate(0deg); }
        100% { transform: rotate(360deg); }
    }
    
    .xc_loading-text {
        color: #6b7280;
        font-size: 12px;
    }
    
    .xc_btn-modern {
        padding: 4px 10px;
        font-size: 12px;
        font-weight: 400;
        border-radius: 3px;
        border: 1px solid #d1d5db;
        background: white;
        color: #374151;
        cursor: pointer;
        transition: all 0.2s;
        display: inline-flex;
        align-items: center;
        gap: 4px;
        white-space: nowrap;
        text-decoration: none;
    }
    
    .xc_btn-modern:hover {
        background: #f9fafb;
        border-color: #3b82f6;
        color: #3b82f6;
    }
    
    .xc_btn-secondary {
        background: white;
        color: #6b7280;
        border: 1px solid #d1d5db;
    }
    
    .xc_btn-secondary:hover {
        background: #f9fafb;
        color: #374151;
        border-color: #9ca3af;
    }

    
    .xc_table-container {
        overflow-x: auto;
        border-radius: 6px;
        border: 1px solid #e5e7eb;
    }
    
    .xc_table {
        width: 100%;
        border-collapse: collapse;
        font-size: 13px;
    }
    
    .xc_table-header {
        background: #fafafa;
        border-bottom: 1px solid #e5e7eb;
    }
    
    .xc_table-header th {
        padding: 10px 12px;
        text-align: left;
        font-weight: 500;
        color: #374151;
        font-size: 13px;
        white-space: nowrap;
    }
    
    .xc_table-body tr {
        border-bottom: 1px solid #e5e7eb;
        transition: background 0.15s;
    }
    
    .xc_table-body tr:nth-child(even) {
        background: #fafbfc;
    }
    
    .xc_table-body tr:last-child {
        border-bottom: none;
    }
    
    .xc_table-body tr:hover {
        background: #f3f4f6 !important;
    }
    
    .xc_table-body td {
        padding: 10px 12px;
        color: #374151;
        vertical-align: middle;
        line-height: 1.5;
    }


    .xc_way-param {
        max-width: 200px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: 12px;
        color: #6b7280;
        font-family: monospace;
    }
    
    .xc_actions {
        display: flex;
        gap: 4px;
    }
    
    .xc_btn-icon {
        padding: 3px 8px;
        font-size: 11px;
        border-radius: 3px;
        border: 1px solid #d1d5db;
        background: white;
        color: #6b7280;
        cursor: pointer;
        transition: all 0.2s;
        display: inline-flex;
        align-items: center;
        gap: 3px;
        text-decoration: none;
    }
    
    .xc_btn-icon:hover {
        background: #f9fafb;
        border-color: #3b82f6;
        color: #3b82f6;
    }
    
    .xc_btn-icon.delete:hover {
        background: #fef2f2;
        border-color: #ef4444;
        color: #ef4444;
    }
    
    .xc_pagination {
        display: flex;
        justify-content: center;
        align-items: center;
        gap: 8px;
        padding: 16px 0;
        background: white;
        border-radius: 6px;
    }
    
    .xc_page-btn {
        min-width: 36px;
        height: 36px;
        padding: 0 12px;
        display: flex;
        align-items: center;
        justify-content: center;
        border: 1px solid #d1d5db;
        background: white;
        color: #6b7280;
        border-radius: 5px;
        cursor: pointer;
        font-size: 13px;
        transition: all 0.2s;
        text-decoration: none;
    }
    
    .xc_page-btn:hover:not(.active) {
        border-color: #3b82f6;
        color: #3b82f6;
    }
    
    .xc_page-btn.active {
        background: #3b82f6;
        color: white;
        border-color: #3b82f6;
    }
    
    .xc_page-info {
        font-size: 13px;
        color: #9ca3af;
        margin: 0 8px;
    }
    
    .xc_empty-state {
        text-align: center;
        padding: 80px 20px;
        color: #9ca3af;
    }
    
    .xc_empty-state i {
        font-size: 64px;
        color: #d1d5db;
        margin-bottom: 16px;
    }
    
    .xc_empty-state p {
        font-size: 14px;
        margin: 0;
    }
    
    /* 算法名称高亮样式 */
    .xc_algorithm-name {
        font-size: 14px;
        font-weight: 600;
        color: #1f2937;
        display: inline-flex;
        align-items: center;
        gap: 6px;
    }
    
    .xc_algorithm-name::before {
        content: '';
        width: 3px;
        height: 14px;
        background: linear-gradient(135deg, #f59e0b, #d97706);
        border-radius: 2px;
        display: inline-block;
    }
    
    .xc_algorithm-code {
        font-size: 11px;
        color: #6b7280;
        font-family: 'Courier New', monospace;
        background: #f3f4f6;
        padding: 2px 6px;
        border-radius: 3px;
        display: inline-block;
    }
    
    .xc_way-badge {
        display: inline-block;
        padding: 3px 8px;
        font-size: 11px;
        border-radius: 12px;
        font-weight: 500;
    }
    
    .xc_way-system {
        background: #dbeafe;
        color: #1e40af;
    }
    
    .xc_way-library {
        background: #e0e7ff;
        color: #4338ca;
    }
    
    .xc_way-api {
        background: #d1fae5;
        color: #065f46;
    }
    
    .xc_way-apiv2 {
        background: #fce7f3;
        color: #9f1239;
    }
    
    .xc_id-badge {
        display: inline-block;
        min-width: 32px;
        text-align: center;
        padding: 2px 8px;
        font-size: 12px;
        font-weight: 500;
        color: #6b7280;
        background: #f9fafb;
        border-radius: 4px;
    }
    
    /* 弹窗样式 */
    .xc_modal-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1000;
    }
    
    .xc_modal-overlay.active {
        display: block;
        animation: xc_fadeIn 0.2s ease;
    }
    
    @keyframes xc_fadeIn {
        from { opacity: 0; }
        to { opacity: 1; }
    }
    
    .xc_modal-container {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        background: white;
        border-radius: 8px;
        width: 90%;
        max-width: 720px;
        max-height: 85vh;
        display: flex;
        flex-direction: column;
        box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
        animation: xc_slideIn 0.3s ease;
    }
    
    @keyframes xc_slideIn {
        from {
            transform: translate(-50%, -48%);
            opacity: 0;
        }
        to {
            transform: translate(-50%, -50%);
            opacity: 1;
        }
    }
    
    .xc_modal-header {
        position: relative;
        padding: 14px 18px;
        border-bottom: 1px solid #e5e7eb;
        background: #fafafa;
        border-radius: 8px 8px 0 0;
    }
    
    .xc_modal-title {
        font-size: 16px;
        font-weight: 500;
        color: #374151;
        display: flex;
        align-items: center;
        gap: 8px;
    }
    
    .xc_modal-title i {
        color: #3b82f6;
    }
    
    .xc_modal-close {
        position: absolute;
        top: 12px;
        right: 16px;
        width: 30px;
        height: 30px;
        border: none;
        background: white;
        color: #6b7280;
        font-size: 20px;
        line-height: 1;
        cursor: pointer;
        padding: 0;
        border-radius: 4px;
        border: 1px solid #d1d5db;
        transition: all 0.2s;
    }
    
    .xc_modal-close:hover {
        background: #f3f4f6;
        color: #374151;
        border-color: #9ca3af;
    }
    
    .xc_modal-body {
        flex: 1;
        padding: 18px 20px;
        overflow-y: auto;
    }
    
    .xc_form-group {
        margin-bottom: 14px;
    }
    
    .xc_form-label {
        display: block;
        font-size: 13px;
        color: #374151;
        margin-bottom: 6px;
        font-weight: 500;
    }
    
    .xc_form-label .required {
        color: #ef4444;
        margin-left: 2px;
    }
    
    .xc_form-input, .xc_form-select, .xc_form-textarea {
        width: 100%;
        padding: 7px 12px;
        font-size: 13px;
        border: 1px solid #d1d5db;
        border-radius: 4px;
        background: white;
        color: #374151;
        transition: all 0.2s;
    }
    
    .xc_form-input {
        height: 36px;
    }
    
    .xc_form-select {
        height: 36px;
    }
    
    .xc_form-textarea {
        resize: vertical;
        font-family: 'Courier New', monospace;
        font-size: 12px;
        min-height: 80px;
    }
    
    .xc_form-input:focus, .xc_form-select:focus, .xc_form-textarea:focus {
        outline: none;
        border-color: #3b82f6;
        box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
    }
    
    .xc_form-input:disabled, .xc_form-select:disabled {
        background: #f3f4f6;
        color: #9ca3af;
        cursor: not-allowed;
    }
    
    .xc_form-hint {
        font-size: 12px;
        color: #9ca3af;
        margin-top: 4px;
        display: block;
    }
    
    .xc_modal-footer {
        padding: 14px 18px;
        border-top: 1px solid #e5e7eb;
        text-align: right;
        background: #fafafa;
        border-radius: 0 0 8px 8px;
    }
    
    .xc_modal-btn {
        padding: 7px 18px;
        font-size: 13px;
        border-radius: 4px;
        border: 1px solid #d1d5db;
        cursor: pointer;
        margin-left: 10px;
        transition: all 0.2s;
        font-weight: 400;
        background: white;
        color: #374151;
    }
    
    .xc_modal-btn:hover {
        background: #f9fafb;
        border-color: #9ca3af;
    }
    
    .xc_modal-btn-primary {
        background: #3b82f6;
        color: white;
        border-color: #3b82f6;
    }
    
    .xc_modal-btn-primary:hover {
        background: #2563eb;
        border-color: #2563eb;
    }
    
    .right_col {
        background: #f5f7fa !important;
    }
    
    @media (max-width: 1200px) {
        .xc_btn-modern {
            padding: 3px 8px;
            font-size: 11px;
        }
    }
    
    @media (max-width: 768px) {
        .xc_page-header {
            flex-wrap: wrap;
            gap: 8px;
        }
        
        .xc_header-right {
            width: 100%;
            justify-content: flex-start;
        }
        
        .xc_table-container {
            overflow-x: scroll;
        }
    }
    
    /* 搜索框样式 */
    .xc_search-box {
        display: flex;
        align-items: center;
        gap: 6px;
        flex-shrink: 0;
    }
    
    .xc_search-input {
        width: 200px;
        height: 30px;
        padding: 0 10px;
        margin-bottom: 5px;
        font-size: 12px;
        border: 1px solid #d1d5db;
        border-radius: 3px;
        transition: border-color 0.2s;
        line-height: 1;
        box-sizing: border-box;
    }
    
    .xc_search-input:focus {
        border-color: #3b82f6;
        outline: none;
    }
    
    .xc_search-input::placeholder {
        color: #9ca3af;
    }

</style>
{% endblock stylesheets %}
{% block content %}
<div class="right_col" role="main">
    <div class="row">
        <div class="col-md-12">
            <div class="x_panel">
                <!-- xc page start -->
                <div class="xc_behaviour-container">
                    <div class="xc_modern-card">
                        <div class="xc_page-header">
                            <div class="xc_page-title">
                                <i class="fa fa-code-fork"></i>
                                行为算法管理
                            </div>
                            <div class="xc_search-box">
                                <input type="text" id="searchInput" class="xc_search-input" placeholder="输入算法名称或编号" value="{{ search_key }}">
                                <button class="xc_btn-modern xc_btn-secondary" onclick="doSearch()">
                                    <i class="fa fa-search"></i> 搜索
                                </button>
                                <button class="xc_btn-modern xc_btn-secondary" onclick="resetSearch()" {% if not search_key %}style="display:none;"{% endif %} id="resetBtn">
                                    <i class="fa fa-times"></i> 重置
                                </button>
                            </div>
                            <div class="xc_header-actions">
                                <button class="xc_btn-modern xc_btn-secondary" onclick="openAddModal()">
                                    <i class="fa fa-plus"></i> 添加
                                </button>
                                <button class="xc_btn-modern xc_btn-secondary" onclick="f_reload()">
                                    <i class="fa fa-refresh"></i> 刷新
                                </button>
                            </div>
                            <div>
                                <span id="top_loading" style="display: none;">
                                    <span class="xc_loading-spinner"></span>
                                    <span class="xc_loading-text">加载中...</span>
                                </span>
                                <span id="top_msg">{{top_msg}}</span>
                            </div>
                        </div>

                        <div class="xc_table-container">
                            <table class="xc_table">
                                <thead class="xc_table-header">
                                    <tr>
                                        <th>ID</th>
                                        <th>算法编号</th>
                                        <th>算法名称</th>
                                        <th>接入方式</th>
                                        <th>接入参数</th>
                                        <th>更新时间</th>
                                        <th style="text-align: center;">操作</th>
                                    </tr>
                                </thead>
                                <tbody class="xc_table-body">
                                    {%  for d  in data %}
                                    <tr>
                                        <td><span class="xc_id-badge">{{ d.id }}</span></td>
                                        <td><span class="xc_algorithm-code">{{ d.code }}</span></td>
                                        <td><span class="xc_algorithm-name">{{ d.name }}</span></td>
                                        <td>
                                            {% if d.way_code == "SYSTEM" %}
                                            <span class="xc_way-badge xc_way-system">{{ d.way_code }}</span>
                                            {% elif d.way_code == "LIBRARY" %}
                                            <span class="xc_way-badge xc_way-library">{{ d.way_code }}</span>
                                            {% elif d.way_code == "API" %}
                                            <span class="xc_way-badge xc_way-api">{{ d.way_code }}</span>
                                            {% elif d.way_code == "APIv2" %}
                                            <span class="xc_way-badge xc_way-apiv2">{{ d.way_code }}</span>
                                            {% else %}
                                            <span class="xc_way-badge">{{ d.way_code }}</span>
                                            {% endif %}
                                        </td>
                                        <td>
                                            <div class="xc_way-param" title="{{ d.way_value }}">{{ d.way_value }}</div>
                                        </td>
                                        <td>{{ d.last_update_time }}</td>
                                        <td>
                                            <div class="xc_actions">
                                                <button onclick="f_edit('{{ d.code }}')" class="xc_btn-icon">
                                                    <i class="fa fa-edit"></i> 编辑
                                                </button>
                                                <button onclick="f_del('{{ d.code }}')" class="xc_btn-icon delete">
                                                    <i class="fa fa-trash"></i> 删除
                                                </button>
                                            </div>
                                        </td>
                                    </tr>
                                    {% endfor %}
                                </tbody>
                            </table>
                            
                            {% if data|length == 0 %}
                            <div class="xc_empty-state">
                                <i class="fa fa-code-fork"></i>
                                <p>暂无行为算法数据</p>
                            </div>
                            {% endif %}
                        </div>
                    </div>

                    <div class="xc_pagination">
                        <span class="xc_page-info">共 {{ pageData.page_num }} 页 / {{ pageData.count }} 条</span>
                        {%  for d  in pageData.pageLabels%}
                          {% if d.cur == 1 %}
                            <div class="xc_page-btn active">{{ d.name }}</div>
                          {% else %}
                            <a href="/behaviour/index?p={{d.page}}&ps={{pageData.page_size}}{% if search_key %}&search={{search_key}}{% endif %}" class="xc_page-btn">{{ d.name }}</a>
                          {% endif %}
                        {% endfor %}
                    </div>
                </div>
                <!-- xc page end -->
            </div>
        </div>
    </div>
</div>

<!-- 添加/编辑弹窗 -->
<div class="xc_modal-overlay" id="behaviourModal">
    <div class="xc_modal-container">
        <div class="xc_modal-header">
            <div class="xc_modal-title" id="modalTitle">
                <i class="fa fa-plus-circle"></i>
                添加行为算法
            </div>
            <button class="xc_modal-close" onclick="closeBehaviourModal()">×</button>
        </div>
        <div class="xc_modal-body">
            <form id="behaviourForm">
                <input type="hidden" id="form_handle" value="add">
                <input type="hidden" id="form_code" value="">
                
                <div class="xc_form-group" id="code_group" style="display: none;">
                    <label class="xc_form-label">算法编号</label>
                    <input type="text" id="input_code_display" class="xc_form-input" disabled>
                    <span class="xc_form-hint">系统自动生成，不可修改</span>
                </div>
                
                <div class="xc_form-group">
                    <label class="xc_form-label">算法名称<span class="required">*</span></label>
                    <input type="text" id="input_name" class="xc_form-input" placeholder="请输入算法名称">
                </div>
                
                <div class="xc_form-group" id="way_code_group">
                    <label class="xc_form-label">接入方式<span class="required">*</span></label>
                    <select id="input_way_code" class="xc_form-select">
                        <option value="0">请选择接入方式</option>
                        <option value="SYSTEM">SYSTEM</option>
                        <option value="LIBRARY">LIBRARY</option>
                        <option value="API">API</option>
                        <option value="APIv2">APIv2</option>
                    </select>
                    <span class="xc_form-hint" id="way_code_hint" style="display: none;">编辑模式下不可修改接入方式</span>
                </div>
                
                <div class="xc_form-group">
                    <label class="xc_form-label">接入参数<span class="required">*</span></label>
                    <textarea id="input_way_value" class="xc_form-textarea" rows="3" placeholder="请输入接入参数"></textarea>
                    <span class="xc_form-hint">根据接入方式填写相应的参数</span>
                </div>
                
                <div class="xc_form-group">
                    <label class="xc_form-label">扩展参数</label>
                    <textarea id="input_extend_params" class="xc_form-textarea" rows="3" placeholder="请输入扩展参数（可选）"></textarea>
                    <span class="xc_form-hint">用于配置额外的扩展参数（可选）</span>
                </div>
            </form>
        </div>
        <div class="xc_modal-footer">
            <button class="xc_modal-btn" onclick="closeBehaviourModal()">取消</button>
            <button class="xc_modal-btn xc_modal-btn-primary" onclick="submitBehaviourForm()">
                <span id="submit_text">提交</span>
            </button>
        </div>
    </div>
</div>

{% endblock content %}

{% block javascripts %}
  {{ block.super }}

<script>
    let ele_top_loading = $("#top_loading");
    let ele_top_msg = $("#top_msg");
    let eleSearchInput = $("#searchInput");
    let eleResetBtn = $("#resetBtn");
    let currentModalMode = 'add'; // 'add' or 'edit'
    let currentBehaviourCode = '';
    
    // 搜索功能
    function doSearch() {
        const searchKey = eleSearchInput.val().trim();
        if (searchKey) {
            window.location.href = '/behaviour/index?search=' + encodeURIComponent(searchKey);
        } else {
            myToast2025('请输入搜索关键词', 'warning');
        }
    }
    
    // 重置搜索
    function resetSearch() {
        window.location.href = '/behaviour/index';
    }
    
    // 支持回车搜索
    eleSearchInput.on('keypress', function(e) {
        if (e.which === 13) {
            doSearch();
        }
    });
    
    // 搜索框变化时显示/隐藏重置按钮
    eleSearchInput.on('input', function() {
        if ($(this).val().trim()) {
            eleResetBtn.show();
        } else {
            eleResetBtn.hide();
        }
    });

    function f_reload() {
        window.location.reload();
    }

    // 打开添加弹窗
    function openAddModal() {
        currentModalMode = 'add';
        currentBehaviourCode = '';
        
        // 设置标题
        $("#modalTitle").html('<i class="fa fa-plus-circle"></i> 添加行为算法');
        $("#form_handle").val('add');
        $("#form_code").val('');
        
        // 隐藏编号字段
        $("#code_group").hide();
        
        // 显示接入方式选择框，启用
        $("#input_way_code").prop('disabled', false);
        $("#way_code_hint").hide();
        
        // 清空表单
        $("#input_code_display").val('');
        $("#input_name").val('');
        $("#input_way_code").val('0');
        $("#input_way_value").val('');
        $("#input_extend_params").val('');
        
        // 显示弹窗
        $("#behaviourModal").addClass('active');
    }

    // 打开编辑弹窗
    function openEditModal(code) {
        currentModalMode = 'edit';
        currentBehaviourCode = code;
        
        // 设置标题
        $("#modalTitle").html('<i class="fa fa-edit"></i> 编辑行为算法');
        $("#form_handle").val('edit');
        $("#form_code").val(code);
        
        // 显示编号字段
        $("#code_group").show();
        
        // 禁用接入方式选择框
        $("#input_way_code").prop('disabled', true);
        $("#way_code_hint").show();
        
        // 显示弹窗
        $("#behaviourModal").addClass('active');
        
        // 加载数据
        ele_top_loading.show();
        $.ajax({
            url: '/behaviour/openEditContext',
            type: "post",
            async: true,
            data: {"code": code},
            dataType: "json",
            timeout: 0,
            error: function () {
                ele_top_loading.hide();
                myToast2025("网络异常，请确定网络正常！", "error");
                closeBehaviourModal();
            },
            success: function (res) {
                ele_top_loading.hide();
                if(1000 === res.code) {
                    let data = res.data;
                    $("#input_code_display").val(data.code);
                    $("#input_name").val(data.name);
                    $("#input_way_code").val(data.way_code);
                    $("#input_way_value").val(data.way_value);
                    $("#input_extend_params").val(data.extend_params);
                } else {
                    myToast2025(res.msg, "error");
                    closeBehaviourModal();
                }
            }
        });
    }

    // 关闭弹窗
    function closeBehaviourModal() {
        $("#behaviourModal").removeClass('active');
    }

    // 提交表单
    function submitBehaviourForm() {
        let name = $("#input_name").val().trim();
        let way_code = $("#input_way_code").val().trim();
        let way_value = $("#input_way_value").val().trim();
        let extend_params = $("#input_extend_params").val().trim();
        
        // 验证
        if(name === "") {
            myToast2025("请输入算法名称", "error");
            $("#input_name").focus();
            return false;
        }
        
        if(way_code === "0" || way_code === "") {
            myToast2025("请选择接入方式", "error");
            $("#input_way_code").focus();
            return false;
        }
        
        if(way_value === "") {
            myToast2025("请输入接入参数", "error");
            $("#input_way_value").focus();
            return false;
        }
        
        let postData = {
            name: name,
            way_code: way_code,
            way_value: way_value,
            extend_params: extend_params,
            remark: ''
        };
        
        let url = '';
        if(currentModalMode === 'add') {
            url = '/behaviour/openAdd';
        } else {
            url = '/behaviour/openEdit';
            postData.code = currentBehaviourCode;
        }
        
        ele_top_loading.show();
        $("#submit_text").text('提交中...');
        
        $.ajax({
            url: url,
            type: "post",
            async: true,
            data: postData,
            dataType: "json",
            timeout: 0,
            error: function () {
                ele_top_loading.hide();
                $("#submit_text").text('提交');
                myToast2025("网络异常，请确定网络正常！", "error");
            },
            success: function (res) {
                ele_top_loading.hide();
                $("#submit_text").text('提交');
                
                if(1000 === res.code) {
                    myToast2025(res.msg, "success");
                    closeBehaviourModal();
                    setTimeout(function() {
                        window.location.reload();
                    }, 800);
                } else {
                    myToast2025(res.msg, "error");
                }
            }
        });
    }

    function f_del(code) {
        if(!confirm('确认删除该行为算法吗？')) {
            return;
        }
        
        ele_top_loading.show();
        $.ajax({
            url: '/behaviour/openDel',
            type: "post",
            async: true,
            data: {"code": code},
            dataType: "json",
            timeout: 0,
            error: function () {
                ele_top_loading.hide();
                myToast2025("网络异常，请确定网络正常！", "error");
            },
            success: function (res) {
                ele_top_loading.hide();
                if(1000 === res.code) {
                    myToast2025("删除成功", "success");
                    setTimeout(function() {
                        window.location.reload();
                    }, 800);
                } else {
                    myToast2025(res.msg, "error");
                }
            }
        });
    }
    
    function f_edit(code) {
        openEditModal(code);
    }
</script>

{% endblock javascripts %}

